package com.graduate.after.web.control;

import com.graduate.after.bean.UserInfo;
import com.graduate.after.constants.StatusCode;
import com.graduate.after.service.UserInfoService;
import com.graduate.after.utils.Result;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;




@Controller
@RequestMapping("/userinfo")
@ResponseBody
public class UserInfoControl {

    private static Logger log = Logger.getLogger(UserInfoControl.class.getClass());
    
    @Autowired
    private UserInfoService userInfoService;

    @RequestMapping("/register")
    public Result registerUser(String username, String password, Long phone) {
        log.info("注册的用户为："+username+",密码为："+password+",手机号为："+phone);
        userInfoService.registerService(username,password,phone);
        return Result.success("Yes");
    }

    @RequestMapping("/login")
    public Result loginUser(String username, String password){
        log.info("登录的用户为："+username+",密码为："+password);
        UserInfo data = userInfoService.loginService(username, password);
        return Result.success(data);
    }

    @RequestMapping("/judge")
    public Result judgeUserName(String username) {
        log.info("判断的的用户为："+username);
        String data = userInfoService.judgeService(username);
        return Result.success(data);

    }

    @RequestMapping("/selectById")
    public Result selectUserNameById(String id) {
        if(StringUtils.isBlank(id)) {
            return Result.fail(StatusCode.PARAM_IS_BLANK);
        }
        String userName = userInfoService.selectUserNameById(Long.parseLong(id));
        System.out.println(userName);
        return Result.success(userName);
    }
}
